{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# hvPlot.contour\n",
    "\n",
    "```{eval-rst}\n",
    ".. currentmodule:: hvplot\n",
    "\n",
    ".. automethod:: hvPlot.contour\n",
    "```\n",
    "\n",
    "## Backend-specific styling options\n",
    "\n",
    "```{eval-rst}\n",
    ".. backend-styling-options:: contour\n",
    "```\n",
    "\n",
    "## Examples\n",
    "\n",
    "### Basic contour lines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray  # noqa\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "\n",
    "x = y = np.linspace(-10, 10, 200)\n",
    "X, Y = np.meshgrid(x, y)\n",
    "Z = 10 * np.exp(-(X**2 + Y**2) / 20)\n",
    "ds = xr.DataArray(Z, coords=[(\"y\", y), (\"x\", x)], name=\"z\").to_dataset()\n",
    "\n",
    "ds.hvplot.contour(x=\"x\", y=\"y\", z=\"z\", levels=10, cmap=\"viridis\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's use a more realistic dataset and plot contours over a 2D field of air temperature for a single time slice."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray # noqa\n",
    "\n",
    "ds = hvplot.sampledata.air_temperature(\"xarray\").sel(time=\"2014-02-25 12:00\")\n",
    "\n",
    "ds.hvplot.contour(x='lon', y='lat', levels=20, cmap='viridis_r')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Specify contour levels and colobar label\n",
    "\n",
    "You can manually control contour levels by setting `levels` to a list of values, and add a colorbar label with `clabel`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.xarray # noqa\n",
    "\n",
    "ds = hvplot.sampledata.air_temperature(\"xarray\").sel(time=\"2014-02-25 12:00\")\n",
    "\n",
    "ds.hvplot.contour(\n",
    "    x='lon', y='lat', z='air', levels=list(range(240, 300, 5)),\n",
    "    cmap='plasma_r', line_width=1.2, clabel='Air Temperature (K)',\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
